import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;
import com.sun.org.apache.bcel.internal.generic.NEW;
import java.io.IOException;
import java.util.Scanner;
import java.util.SplittableRandom;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 9:04
 * @description:
 */
public class UserText {
private static UserDao dao=new UserDaoIO();
  public static void main(String[] args){
    while (true){
    System.out.println("---------欢迎各广陵--------");
    System.out.println("1、注册");
    System.out.println("2、登陆");
    System.out.println("3、查询");
    System.out.println("4、退出");
    System.out.println("请输入一个数");
    Scanner sc=new Scanner(System.in);
    int num=sc.nextInt();

      switch (num){
        case 1:
          registerFace();
          break;
        case 2:
          loginFace();
          break;
        case 3:
          queryAllFace();
          break;
        case 4:
          System.out.println("欢迎下次光临");
          System.exit(0);
          break;
        default:
            break;
      }

    }
  }

  private static void queryAllFace() {
    System.out.println("查询界面");

    dao.quiteAll();

  }

  private static void loginFace() {
    System.out.println("-----登陆界面-----");
    Scanner sc1=new Scanner(System.in);
    Scanner sc2=new Scanner(System.in);
    System.out.println("请输如账户");
    String name=sc1.nextLine();
    System.out.println("请输入密码");
    String password=sc2.nextLine();
    boolean flag=dao.login(name,password);
    if (flag){
      System.out.println("登陆成功");
    }else {
      System.out.println("登录失败");
    }
  }

  private static void registerFace()  {
    System.out.println("-----注册界面-----");
    Scanner sc1=new Scanner(System.in);
    Scanner sc2=new Scanner(System.in);
    System.out.println("请输入id");
    int id=sc1.nextInt();
    System.out.println("请输如账户");
    String name=sc2.nextLine();
    System.out.println("请输入密码");
    String password=sc2.nextLine();
    System.out.println("请输入年龄");
    int age=sc1.nextInt();
    User user=new User(id,name,password,age);
    try {
      dao.register(user);
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println("注册成功");

  }


}
